package ObjectOrientedTest5;

public class GirlFriendTest {
    public static void main(String[] args) {
        //1.定义数组数组存入女朋友的对象
        GirlFriend[] arr=new GirlFriend[4];

        //2.创建女朋友对象
        GirlFriend gf1=new GirlFriend("1",18,"妹子","吃零食");
        GirlFriend gf2=new GirlFriend("2",19,"妹子","玩游戏");
        GirlFriend gf3=new GirlFriend("3",20,"妹子","看书，学习");
        GirlFriend gf4=new GirlFriend("4",21,"妹子","睡觉");

        //3.把对象添加到数组中
        arr[0]=gf1;
        arr[1]=gf2;
        arr[2]=gf3;
        arr[3]=gf4;

        //4.求和
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend girlFriend=arr[i];
            sum=girlFriend.getAge()+sum;
        }

        //5.平均值
        int avg=sum/arr.length;

        //6.统计年龄比平均值低的有几个，打印他们的信息
        int count = 0;
        for (int i = 0; i <  arr.length; i++) {
            GirlFriend girlFriend=arr[i];
            if(girlFriend.getAge()<avg){
                count++;
                System.out.println(girlFriend.getName()+","+girlFriend.getAge()+","+girlFriend.getGender()+","+girlFriend.getHobby());
            }
        }

        System.out.println(count+"个");

    }
}
